package com.example.dell.library.activity;


import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentTransaction;
import android.support.v7.app.AppCompatActivity;
import com.example.dell.library.fragment.HomeFragment;
import com.example.dell.library.fragment.ManagerFragment;
import com.example.dell.library.fragment.MineFragment;
import com.example.dell.library.R;
import com.example.dell.library.fragment.SearchFragment;
import com.google.gson.Gson;
import com.roughike.bottombar.BottomBar;
import com.roughike.bottombar.OnTabSelectListener;

import butterknife.ButterKnife;

public class MainActivity extends AppCompatActivity {
    private BottomBar bottomBar;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        bottomBar = (BottomBar) findViewById(R.id.bottomBar);
        initListener();
        ButterKnife.bind(this);
    }

    private void initListener() {
        bottomBar.setOnTabSelectListener(new OnTabSelectListener() {
            @Override
            public void onTabSelected(int tabId) {
                Fragment fragment = null;
                switch (tabId) {
                    case R.id.tab_home:
                        fragment = new HomeFragment();
                        break;
                    case R.id.tab_search:
                        fragment = new SearchFragment();
                        break;
                    case R.id.tab_manager:
                        fragment = new ManagerFragment();
                        break;
                    case R.id.tab_mine:
                        fragment = new MineFragment();
                        break;
                    default:
                        break;
                }
                FragmentTransaction fragmentTransaction = getSupportFragmentManager().beginTransaction();
                fragmentTransaction.replace(R.id.container, fragment, fragment.getClass().getSimpleName());
                fragmentTransaction.commit();
            }
        });
    }
}
